package com.house.api.controller;

import com.house.common.result.Result;

import com.house.model.dto.HouseDto;
import com.house.model.dto.HouseLocationDto;
import com.house.model.entity.House;
import com.house.model.vo.HouseInfoVo;
import com.house.model.vo.SearchHouseVo;
import com.house.service.service.IHouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.house.model.vo.HouseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Set;

@RestController
@Slf4j
@Api(tags = "卖房相关接口")
@RequestMapping("/house")
public class HouseController {

    @Autowired
    private IHouseService houseService;

    @ApiOperation("卖房")
    @PostMapping("/addSellers")
    public Result sellers(@RequestBody House house){
        houseService.addSellers(house);
        return Result.ok();
    }

    @GetMapping("/search/{addr}")
    public Result searchHouseList(@PathVariable("addr")String addr) {
        List<SearchHouseVo> searchHouseVos = houseService.searchHouseList(addr);
        return Result.ok(searchHouseVos);
    }

    @PostMapping("/list")
    public Result list(@RequestBody HouseLocationDto dto){
        List<HouseVo> list = houseService.houseList(dto);
        return Result.ok(list);
    }

    @GetMapping("/getOne/{houseId}")
    public Result getOne(@PathVariable("houseId")String houseId){
        HouseVo houseVoOne = houseService.getHouseVoOne(houseId);
        return Result.ok(houseVoOne);
    }

    @GetMapping("/info/{houseId}")
    public Result info(@PathVariable("houseId") String houseId){
        HouseInfoVo list =houseService.houseInfo(houseId);
        return Result.ok(list);
    }

    @PostMapping ("/getHouse")
    public Result getHoseById(@RequestBody HouseDto dto) {
        House houseById = houseService.getHouseById(dto);
        return Result.ok(houseById);
    }

    @GetMapping("/houseListById")
    public Result getHouseListById() {
        List<HouseVo> houseListById = houseService.getHouseListById();
        return Result.ok(houseListById);
    }

    @GetMapping ("/oneself/{userId}")
    public Result isOneself(@PathVariable String userId) {
        boolean houseByOneself = houseService.isHouseByOneself(userId);
        return Result.ok(houseByOneself);
    }

    @GetMapping("/hotsearch")
    @ApiOperation(value = "查询热门搜索词")
    public Result getHotSearch() {
        Set<Object> hotSearch = houseService.getHotSearch();
        return Result.ok(hotSearch);
    }
}
